package com.dic.mall.search.controller;

import com.dic.common.exception.BizCodeEnum;
import com.dic.common.utils.R;
import com.dic.common.vo.es.SkuEsModel;
import com.dic.mall.search.service.ProductSaveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

/**
 * @author ：leeliang
 * @date ：Created in 2021/3/12 1:33
 * @description：
 * @modified By：
 * @version: $
 */
@RestController
@RequestMapping("/search")
public class ElasticSearchController {
    @Autowired
    private ProductSaveService productSaveService;
    @PostMapping("/product")
    public R productStatusUp(@RequestBody List<SkuEsModel> skuEsModelList){
        Boolean aBoolean = false;
        try {
            aBoolean = productSaveService.productStatusUp(skuEsModelList);
        } catch (IOException e) {
            return R.error(BizCodeEnum.PRODUCT_UP_EXCEPTION.getCode(),BizCodeEnum.PRODUCT_UP_EXCEPTION.getMessage());
        }
        if(aBoolean){
            return R.ok();
        }else{
            return R.error(BizCodeEnum.PRODUCT_UP_EXCEPTION.getCode(),BizCodeEnum.PRODUCT_UP_EXCEPTION.getMessage());
        }
    }
}
